package com.weiyin.examination.module;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Created by darkshadow on 2018/7/25.
 */

public class Note implements Parcelable {
    /**
     * 附点
     */
    private String dot;
    /**
     * 休止符
     */
    private String rest;
    /**
     * note值
     */
    private String pitch;
    /**
     * 三连音
     */
    private String actualNotes;
    private String normalNotes;
    private String normalType;
    /**
     * 音符样式
     */
    private String type;
    /**
     * 同音连线
     */
    private String tied;
    private BitMapModule bitMapModule;

    protected Note(Parcel in) {
        dot = in.readString();
        rest = in.readString();
        pitch = in.readString();
        actualNotes = in.readString();
        normalNotes = in.readString();
        normalType = in.readString();
        type = in.readString();
        tied = in.readString();
        bitMapModule = in.readParcelable(BitMapModule.class.getClassLoader());
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(dot);
        dest.writeString(rest);
        dest.writeString(pitch);
        dest.writeString(actualNotes);
        dest.writeString(normalNotes);
        dest.writeString(normalType);
        dest.writeString(type);
        dest.writeString(tied);
        dest.writeParcelable(bitMapModule, flags);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<Note> CREATOR = new Creator<Note>() {
        @Override
        public Note createFromParcel(Parcel in) {
            return new Note(in);
        }

        @Override
        public Note[] newArray(int size) {
            return new Note[size];
        }
    };

    public void setBitMapModule(BitMapModule bitMapModule) {
        this.bitMapModule = bitMapModule;
    }

    public BitMapModule getBitMapModule() {
        return bitMapModule;
    }


    public Note() {

    }

    public void setPitch(String pitch) {
        this.pitch = pitch;
    }

    public String getPitch() {
        return pitch;
    }

    public String getActualNotes() {
        return actualNotes;
    }

    public void setActualNotes(String actualNotes) {
        this.actualNotes = actualNotes;
    }

    public String getNormalNotes() {
        return normalNotes;
    }

    public void setNormalNotes(String normalNotes) {
        this.normalNotes = normalNotes;
    }

    public String getNormalType() {
        return normalType;
    }

    public void setNormalType(String normalType) {
        this.normalType = normalType;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getTied() {
        return tied;
    }

    public void setTied(String tied) {
        this.tied = tied;
    }

    public String getDot() {
        return dot;
    }

    public void setDot(String dot) {
        this.dot = dot;
    }

    public String getRest() {
        return rest;
    }

    public void setRest(String rest) {
        this.rest = rest;
    }

    public boolean equalsNote(Note note, boolean isTied, boolean isActualNotes) {
        if (note.getRest().equals(this.getRest())
                && note.getDot().equals(this.getDot())
                && note.getType().equals(this.getType())) {
            if (note.getRest().equals("false")) {
                if (note.getPitch().equals(this.getPitch())) {
                    if (isActualNotes) {
                        return note.getNormalNotes().equals("true")
                                && note.getNormalType().equals(note.getNormalType());
                    } else {
                        return !isTied || note.getTied().equals("true");
                    }
                } else {
                    return false;
                }
            } else {
                return true;
            }
        } else {
            return false;
        }

    }
}